#ifndef __CARD_H_
#define __CARD_H_
// Includes
#include "kl_lib_l15x.h"
#include "string.h"

// ============================== Timings ======================================
#define CRD_RETRY_TIMEOUT   496  // ms
#define CRD_REPLY_TIMEOUT   4005  // ms

// =============================== Variables ===================================
typedef enum { csIdle, csBusy, csCmdFail, csHwFail, csOut } CardState_t;
typedef enum { ctMifare, ctJCop, ctInfineon } CardType_t;

class Card_t {
private:
    uint16_t Timer;
public:
    bool IsMifare;
    CardState_t State;
    CardType_t Type;
    // ATR section

    uint8_t *ATQB; // ATQb for 14443-B type
    uint8_t Buf[279];
    uint8_t ATR_Buf[36], ATR_Length;    // Buffer to store ATR
    uint16_t DataLength;
    uint8_t NAD, IFSC, BWI_CWI_T1, WI_T0, FindexDindex;
    //void DetermineType(void);
    void ConfigATR(uint8_t* PBufATR, uint16_t Length);
    void ClearATR()     { memset(ATR_Buf, 0, 36); }
    void ConstructATR();
};

extern Card_t Card;

#endif
